<template>
  <page-header-wrapper>
    <global-search ref="globalSearch" :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        :rowKey="(record, index) => index"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getStatementList } from '@/api/statementAndStatistics'
export default {
  components: {
    STable,
    Ellipsis
  },
  data () {
    return {
      searchList: [
        {
          label: '年度',
          fields: 'Years',
          type: 'year',
          props: {
            placeholder: '请选择年度'
          }
        },
        {
          label: '季度',
          fields: 'Quarter',
          type: 'select',
          props: {
            placeholder: '请选择季度',
            options: [
              {
                label: '第一季度',
                value: 1
              },
              {
                label: '第二季度',
                value: 2
              },
              {
                label: '第三季度',
                value: 3
              },
              {
                label: '第四季度',
                value: 4
              }
            ]
          }
        }
      ],
      queryParam: {
        Mode: 'KZFY',
        UserID: this.$store.getters.userid,
        strContent: {}
      },
      columns: [
        {
          title: '序号',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '计划名称',
          align: 'center',
          dataIndex: 'JHMC'
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'XMMC'
        },
        {
          title: '房屋地址',
          align: 'center',
          dataIndex: 'FWXX'
        },
        {
          title: '房屋编号',
          align: 'center',
          dataIndex: 'FWID'
        },
        {
          title: '户型',
          align: 'center',
          dataIndex: 'HX'
        },
        {
          title: '面积',
          align: 'center',
          dataIndex: 'MJ'
        },
        {
          title: '房源所属',
          align: 'center',
          dataIndex: 'FWSS'
        },
        {
          title: '年度',
          align: 'center',
          dataIndex: 'Years'
        },
        {
          title: '季度',
          align: 'center',
          dataIndex: 'Quarter'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getStatementList(requestParameters).then((res) => res)
      }
    }
  },
  methods: {
    handleSearch (values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset () {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh (refresh = false) {
      this.$refs.table.refresh(refresh)
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
